class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int minprice = prices[0];
        int ret = 0;
        int n = prices.size();
        for(int i = 1;i<n;i++)
        {
            ret = max(ret,prices[i]-minprice);
            minprice = min(prices[i],minprice);
        }
        return ret;
    }
};